/**
 * Created by maxwell on 16/10/7.
 */
"use strict";
let router = require('koa-router')();
let config = require('../../config');
let commonService = require("../../service/common/service");
let _ = require("underscore");

router.get("/userInfo", function *() {
    let access_token = this.cookies.get('access_token');
    let userInfo = {};
    if (!access_token) {
        this.redirect('login');
    } else {
        userInfo = yield commonService.getCurrentUserInfo({
            token: access_token
        });
        try {
            yield this.render('user/info', _.extend(userInfo, {uri: config['apiHost']['uri']}));
        } catch (e) {
            this.redirect('sysError');
            throw new Error(e);
        }
    }
});

module.exports = router;